<?php
/**
 * Created by PhpStorm.
 * User: baidu
 * Date: 17/8/6
 * Time: 上午2:45
 */

namespace app\common\lib\exception;

use think\exception\Handle;
use think\App;
use think\exception\HttpException;
use think\Log;
use think\Config;

class WebHandleException extends Handle
{

    /**
     * http 状态码
     * @var int
     */
    public $httpCode = 200;
    public $code = 0;
    public $message = '服务异常，稍后重试。';

    public function render(\Exception $e)
    {
        if ($this->render && $this->render instanceof \Closure)
        {
            $result = call_user_func_array($this->render, [$e]);
            if ($result)
            {
                return $result;
            }
        }

        if ($e instanceof HttpException)
        {
            return $this->renderHttpException($e);
        } else
        {
            $result = $this->convertExceptionToResponse($e);

            if ($result->getCode() === 500)
            {
                $result->code(200);
            }

            return $result;
        }
    }
}
